package dem1;

import java.util.ArrayList;
import java.util.Stack;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-04-12
 * Time: 8:45
 */

class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (String s : tokens) {
            if (oper(s)) {
                int x = stack.pop();
                int y = stack.pop();
                switch (s) {
                    case "*":
                        stack.push(x * y);
                        break;
                    case "-":
                        stack.push(y - x);
                        break;
                    case "+":
                        stack.push(x + y);
                        break;
                    case "/":
                        stack.push(y / x);
                        break;
                    default:
                        break;
                }
            } else {
                stack.push(Integer.parseInt(s));
            }
        }
        return stack.peek();
    }

    private boolean oper(String s){
        if(s.length() == 1 && (s.charAt(0) == '+' || s.charAt(0) == '-'
                || s.charAt(0) == '*' || s.charAt(0) == '/')){
            return true;
        }
        return false;
    }
}

public class Test {
    public static void main(String[] args) {
        Stack<Character> stack = new Stack<>();
        ArrayList<Integer> list = new ArrayList<>();
        list.contains(1);
        //String str = "dads";
    }
}
